package com.syn.gmail.search.controller;

import com.syn.common.exception.BizCodeEnume;
import com.syn.common.to.es.SkuEsModel;
import com.syn.common.utils.R;
import com.syn.gmail.search.service.ProductSaveService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;
@Slf4j
@RequestMapping("/serach/save")
@RestController
public class ProductSaveController {
    @Autowired
    ProductSaveService productSaveService;

    @PostMapping("/product")
    public R savaProduct(@RequestBody List<SkuEsModel> skuEsModelList) throws IOException {
        boolean flag = false;
        try {
            flag  = productSaveService.productUp(skuEsModelList);
        }catch (Exception e){
            log.error("ProductSaveController上架错误,{}",e);
            return R.error(BizCodeEnume.PRODUCT_EXCEPTION.getCode(),BizCodeEnume.PRODUCT_EXCEPTION.getMsg());
        }
        if(!flag) return R.ok();
        return R.error(BizCodeEnume.PRODUCT_EXCEPTION.getCode(),BizCodeEnume.PRODUCT_EXCEPTION.getMsg());
    }


}
